import Vue from 'vue'
import Router from 'vue-router'

// 前台首页
import Home from './views/Home.vue'
// home的子路由
import Hindex from './views/home/hindex.vue'

import Fupinview from './views/home/FuPin.vue'
import FupinInfo from './views/home/FuPinInfo.vue'

import PinKunview from './views/home/PinKun.vue'
import PinKunInfo from './views/home/PinKunInfo.vue'

import ZhiYuanview from './views/home/ZhiYuan.vue'
import ZhiYuanInfo from './views/home/ZhiYuanInfo.vue'
import ZhiYuanYP from './views/home/ZhiYuanYP.vue'

import LiuYan from './views/home/LiuYan.vue'

import Userview from './views/home/User.vue'

// 后台登录
import Login from './views/Login.vue'
// 后台管理
import Main from './views/Main.vue'
// main的子路由
import Fupin from './views/main/Fupin.vue'
import Index from './views/main/Index.vue'
import Zhiyuanzhe from './views/main/Zhiyuanzhe.vue'
import Liuyanban from './views/main/Liuyanban.vue'
import Pinkunhu from './views/main/Pinkunhu.vue'
import User from './views/main/User.vue'
import Lunbotu from './views/main/Lunbotu.vue'
import Shoucang from './views/main/Shoucang.vue'

Vue.use(Router)

var router= new Router({
  mode:'history',
  routes: [
    {
      path:'/login',
      name:'login',
      component:Login
    },
    {
      path: '/',
      name: 'home',
      component: Home,
      redirect:'/hindex',
      children:[
        {
          path:'/hindex',
          component:Hindex
        },
        {
          path:'/fupinview',
          component:Fupinview
        },
        {
          path:'/fupinview/fupininfo/:id',
          component:FupinInfo
        },
        {
          path:'/pinkunview',
          component:PinKunview
        },
        {
          path:'/pinkunview/pinkuninfo/:id',
          component:PinKunInfo
        },
        {
          path:'/zhiyuanview',
          component:ZhiYuanview
        },
        {
          path:'/zhiyuanview/zhiyuaninfo/:id',
          component:ZhiYuanInfo
        },
        {
          path:'/zhiyuanview/zhiyuaninfo/yingpin:id',
          component:ZhiYuanYP
        },
        {
          path:'/liuyan',
          component:LiuYan
        },
        {
          path:'/userview',
          component:Userview
        },
      ]
    },
    {
      path: '/main',
      name: 'main',
      component: Main,
      redirect:'/index',
      children:[
        {
          path:'/index',
          name:'index',
          component:Index
        },
        {
          path:'/fupin',
          name:'fupin',
          component:Fupin
        },
        {
          path:'/zhiyuanzhe',
          name:'zhiyuanzhe',
          component:Zhiyuanzhe
        },
        {
          path:'/liuyanban',
          name:'liuyanban',
          component:Liuyanban
        },
        {
          path:'/pinkunhu',
          name:'pinkunhu',
          component:Pinkunhu
        },
        {
          path:'/user',
          name:'user',
          component:User
        },
        {
          path:'/lunbotu',
          name:'lunbotu',
          component:Lunbotu
        },
        {
          path:'/shoucang',
          name:'shoucang',
          component:Shoucang
        }
      ]
    },
   
  ]
})
router.beforeEach((to, from, next) => {
  // to 即将要访问的路径
  // from 从哪个路径来
  // next 放行
// window.sessionStorage.setItem('token',"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiLmnYPpmZDpqozor4EiLCJyb2xlIjoiYWRtaW4iLCJzYWx0IjoiMjA1NTEyIiwiaXNzIjoiYWRtaW4iLCJpZCI6MSwiZXhwIjoxNjUxNTc0NTQwLCJpYXQiOjE2NTE0ODgxNDAsInVzZXJuYW1lIjoi5piT54OK5Y2D5466In0.wfTh2YOD8iHMkS_OuQIGtTRSsAdIC04JWwR7NXKQvuE")
window.console.log(to.path);
 if(to.path=='/login')return next();
 const tokenstr=sessionStorage.getItem('token');
//  if(to.path=='/userview'||!tokenstr) return next('/login');
 if(!tokenstr) return next('/login')
 next();
})
export default router